package com.ccb.sc.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ccb.sc.order.vo.ShoppingCartItemVo;
import com.ccb.sc.common.modules.shopkeeper.entity.ShoppingCart;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 购物车 Mapper 接口
 * </p>
 *
 * @author ken
 * @since 2020-09-24
 */
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {


    List<ShoppingCartItemVo> selectByMemberId(@Param("memberId") Long memberId, @Param("selected") Boolean selected);

    @Update({
        "<script>",
            "update",
            "tb_shopping_cart",
            "set selected=#{selected}",
            "where member_id=#{memberId} and goods_specs_id in",
            "<foreach collection='goodsSpecsIds' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
        "</script>"
    })
    void changeSelected(Long memberId, Long[] goodsSpecsIds, Boolean selected);

    @Update({
        "<script>",
            "update",
            "tb_shopping_cart",
            "set selected=#{selected}",
            "where member_id=#{memberId}",
        "</script>"
    })
    void changeAllSelected(Long memberId, Boolean selected);
}
